package com.example.apidocserver.application.event.impl;

import com.example.apidocserver.application.event.SystemEvent;
import com.example.apidocserver.domain.system.entity.AllEnum;
import com.example.apidocserver.domain.space.event.AllEnumDomainEvent;
import com.example.apidocserver.interfaces.dto.IdsDto;
import com.example.apidocserver.interfaces.vo.AllEnumVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 系统事件
 *
 * @author xyqlg
 */
@Service
public class SystemEventImpl implements SystemEvent {
    @Resource
    private AllEnumDomainEvent allEnumDomainEvent;

    @Override
    public AllEnumVo findAllEnum() {
        return allEnumDomainEvent.findAllEnum();
    }

    @Override
    public AllEnum upsertAllEnum(AllEnum allEnum) {
        return allEnumDomainEvent.upsertAllEnum(allEnum);
    }

    @Override
    public int deleteAllEnum(Integer id) {
        return allEnumDomainEvent.deleteAllEnum(id);
    }

    @Override
    public List<AllEnum> getByTypeList(IdsDto ids) {
        return allEnumDomainEvent.getByTypeList(ids);
    }

    @Override
    public AllEnum getByType(Integer id) {
        if (Objects.isNull(id)) {
            return new AllEnum();
        }
        IdsDto idsDto = new IdsDto();
        idsDto.setIds(Collections.singletonList(id));
        List<AllEnum> list = allEnumDomainEvent.getByTypeList(idsDto);
        if (list.isEmpty()) {
            return new AllEnum();
        }
        return list.get(0);
    }
}
